package com.frikinet.lifeguard.dao;

import com.frikinet.lifeguard.model.Post;
import com.frikinet.lifeguard.model.User;
import com.frikinet.lifeguard.util.HibernateUtil;

public class UserDAO
{
	public static void saveOrUpdate(User user)
	{
		HibernateUtil.saveOrUpdate(user);
		for(Post post: user.getPosts())
		{
			PostDAO.saveOrUpdate(post);
		}
	}
	
	public static void delete(User user)
	{
		for(Post post: user.getPosts())
		{
			PostDAO.delete(post);
		}
		user.getPosts().clear();
		HibernateUtil.delete(user);
	}
}
